
package com.test;

import java.util.ArrayList;
import java.util.List;


import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


public class SMILPlayerList extends ListActivity
{

    private Handler mHandler = new Handler();


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<SMILMessage>(this, R.layout.list_item, getSMILMessages()));

        ListView lv = getListView();
        lv.setTextFilterEnabled(true);

        lv.setOnItemClickListener(new OnItemClickListener()
        {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                // When clicked, show a toast with the TextView text
                Intent myIntent = new Intent(view.getContext(), SMILPlayer.class);
                myIntent.putExtra("message", getSMILMessages().get(position));
                startActivity(myIntent);
            }
        });

    }


    private List<SMILMessage> getSMILMessages()
    {
        List<SMILMessage> messages = new ArrayList<SMILMessage>();
        SMILMessage message;
        SequenceSeries series;
        SMILTextComponent comp;

        for (int x = 1; x <= 20; ++x)
        {
            message = SMILMessage.create();
            series = SequenceSeries.create();
            comp = SMILTextComponent.create();

            comp.setDuration(5);
            comp.setText("Message " + x);

            series.addComponent(comp);
            message.addSeries(series);

            message.setSubject("Message " + x);

            messages.add(message);

        }
        return messages;
    }
}